package main

import (
	"flag"
	"fmt"
	"grpc.getaway.adminspro.padmins.com/internal/api/module/admin/bootstrap"
	"log"
	"net/http"
	"strconv"
	"time"
)

func main() {
	httpPort := flag.Int("port", 8001, "api-admin default listen port 8001")
	flag.Parse()

	http.Handle("/ping", http.TimeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "pong")
	}), 20*time.Second, "Timeout"))

	http.Handle("/getaway", http.TimeoutHandler(http.HandlerFunc(bootstrap.Handler), 20*time.Second, "Timeout"))

	httpServer := http.Server{
		Addr:              "0.0.0.0:" + strconv.Itoa(*httpPort),
		Handler:           nil,
		ReadTimeout:       time.Second * 2,
		ReadHeaderTimeout: time.Second * 2,
		WriteTimeout:      time.Second * 5,
		IdleTimeout:       time.Second * 2,
	}

	if e := httpServer.ListenAndServe(); e != nil {
		log.Fatalf("error in ListenAndServe: %s", e)
	}
}
